package pers.li.service;

import pers.li.dao.GoodsDao;
import pers.li.model.Goods;
import pers.li.model.TO.CarTO;
import pers.li.model.VO.CarVO;
import pers.li.utils.BeanCopy;
import java.util.List;

public class CarService {
    private final GoodsDao goodsDao = new GoodsDao();

    public CarVO getCarVOByTO(CarTO carTO) {
        Integer goodId = carTO.getGoodId();
        List<String> typeName = carTO.getTypeName();
        Integer goodsSales = carTO.getGoodsSales();
        List<Integer> tyList = carTO.getTypeList();
        Goods goods = goodsDao.getGoodsByGoodId(goodId);
        CarVO carVO = new CarVO();
        assert goods != null;
        BeanCopy.copy(goods, carVO);
        carVO.setSales(goodsSales);
        carVO.setContentId(tyList);
        carVO.setContentName(typeName);
        final StringBuilder trId = new StringBuilder();
        trId.append(goodId);
        tyList.forEach(trId::append);
        carVO.setTrId(trId.toString());
        return carVO;
    }
}
